home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2004 #2 / Amiga Plus CD - 2004 - No. 02.iso / AmiSoft / Misc / emu / Wzonka-Lad.lha / Wzonka-Lad / src / aga_screen_draw.s next >
Text File  |  1999-05-04  |  20KB  |  778 lines

  1.  
  2. ;««««««««««««««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
  3. ;        screen draw aga - the third generation routines 8D
  4. ;««««««««««««««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
  5.  
  6.         cnop    0,4
  7. aga_screen_draw:move.l    a2,a6                ;a6 = the fixed 16bit
  8.         add.l    #$ff40,a6            ;a6 = lcd control.
  9.         moveq.l    #0,d7
  10.         move.b    (a6),d7                ;d7 = lcd control byte.
  11.         btst    #7,d7                ;lcd operation?
  12.         beq.s    clear_aga_screen        ;no. clear and quit.
  13.         move.l    d7,lcd_control            ;store the byte.
  14.  
  15.         bsr.w    push_z80
  16.  
  17.         move.l    aga_map_inactive,d6
  18.         cmp.l    aga_map_I,d6
  19.         beq.s    wait_I
  20. wait_II:    tst.b    visual_frame
  21.         bne.s    wait_II
  22.         bra.s    wait_done
  23. wait_I:        tst.b    visual_frame
  24.         beq.s    wait_I
  25.  
  26. wait_done:    bsr.w    screen_aga_bg
  27.         bsr.w    screen_aga_win
  28.         bsr.w    screen_aga_sprs
  29.         bsr.w    update_aga_pal
  30.         bsr.w    swap_aga_buffex            ;swap the lists.
  31.  
  32.         bsr.w    pull_z80
  33.         rts
  34.  
  35. ;««««««««««««««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
  36. ;        clear screen
  37. ;««««««««««««««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
  38.  
  39. clear_aga_screen:
  40.         bsr.w    push_z80
  41.  
  42.         move.l    aga_map_inactive,d6
  43.         cmp.l    aga_map_I,d6
  44.         beq.s    wait_In
  45. wait_IIn:    tst.b    visual_frame
  46.         bne.s    wait_IIn
  47.         bra.s    wait_donen
  48. wait_In:    tst.b    visual_frame
  49.         beq.s    wait_In
  50.  
  51. wait_donen:    clr.l    lcd_control            ;sprites off -> clear.
  52.                             ;window off -> clear.
  53.                             ;background off -> clear.
  54.         bsr.w    screen_aga_bg
  55.         bsr.w    screen_aga_win
  56.         bsr.w    screen_aga_sprs
  57.         bsr.w    update_aga_pal            ;update the palette.
  58.         bsr.w    swap_aga_buffex            ;swap the lists.
  59.  
  60.         bsr.w    pull_z80
  61.         rts
  62.  
  63. ;««««««««««««««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
  64. ;        execute the background copying
  65. ;««««««««««««««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
  66.  
  67.         cnop    0,4
  68. screen_aga_bg:    move.l    d7,d0                ;d0 = lcd control byte.
  69.         btst    #0,d0                ;background display?
  70.         beq.w    screen_aga_clear_the_background    ;no. quit.
  71.  
  72.         move.l    gb_memory,a0            ;a0 = the fixed 16bit
  73.         move.l    a0,a1                ;memory area.
  74.         add.l    #$ff42,a1            ;a1 = lcd control.
  75.         moveq.l    #0,d2
  76.         move.b    (a1)+,d2            ;d2 = bg scroll y.
  77.         moveq.l    #0,d3
  78.         move.b    (a1),d3                ;d3 = bg scroll x.
  79.  
  80.         move.l    d0,d1                ;d1 = the control byte.
  81.         and.b    #%1000,d0            ;d0 = background tiles.
  82.         lsl.w    #7,d0                ;0/1 * 1024.
  83.         move.l    a0,a1
  84.         add.l    #$9800,a1            ;tile position.
  85.         add.l    d0,a1                ;selected position.
  86.                             ;a1 = input tiles.
  87.         and.b    #%10000,d1            ;d1 = background tile
  88.         move.l    d1,d7                ;datas. 0/1 * 2048.
  89.         lsl.b    #3,d7                ;d7 = tile adder (signed/
  90.         bchg    #7,d7                ;unsigned).
  91.         move.l    d7,tile_adder
  92.         lsl.w    #7,d1
  93.         move.l    a0,a2
  94.         add.l    #$8800,a2            ;tile data position.
  95.         sub.l    d1,a2                ;selected position.
  96.                             ;a2 = input tile datas.
  97.         move.l    a2,gb_tiles
  98.  
  99. ;««««««««««««««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
  100. ;        copy background data
  101. ;        INPUT:
  102. ;        d2    = background scroll y.
  103. ;        d3    = background scroll x.
  104. ;        a1    = tiles.
  105. ;        a2    = tile datas.
  106. ;««««««««««««««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
  107.  
  108.         move.l    d2,d4
  109.         lsr.w    #3,d2                ;d2 = number of rows
  110.                             ;to be skipped.
  111.         move.b    d2,d6                ;when d6=32 then back to y=0.
  112.  
  113.         lsl.w    #5,d2                ;d2 = d2 * 32 (start y).
  114.         add.l    d2,a1                ;y of tiles = done.
  115.  
  116.         move.l    d3,d5
  117.         lsr.w    #3,d3                ;d3 = x start.
  118.         move.b    d3,d7                ;when d7=32 then back to x=0.
  119.  
  120.         move.l    bg_scroll_inactive,a0
  121.         and.b    #%111,d4            ;d4 = y pixel scroll (0-7).
  122.         and.b    #%111,d5            ;d5 = x pixel scroll (0-7).
  123.         move.l    d4,(a0)                ;store the scroll value.
  124.         moveq.l    #8,d0
  125.         sub.b    d5,d0
  126.         move.l    aga_ro_inactive,a0
  127.         move.b    d0,(a0)                ;new x h/w shift value used.
  128.  
  129. ;««««««««««««««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
  130. ;        INPUT:
  131. ;        d6    = (background start y) / 8.
  132. ;        d7    = (background start x) / 8.
  133. ;        a1    = tiles.
  134. ;        a2    = tile pattern datas.
  135. ;««««««««««««««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
  136.  
  137.         move.l    aga_map_inactive,a0        ;a0 = p0.
  138.         add.l    #40*8*16+64/8-1,a0        ;position fix.
  139.         moveq.l    #(144/8)+1-1,d0            ;y.
  140.         move.l    tile_adder,d2            ;d2 = tile adder.
  141.         moveq.l    #0,d3                ;speed up.
  142.  
  143.         cnop    0,4
  144. screen_aga_colu:movem.l    d6/d7/a0,-(SP)
  145.         moveq.l    #8-1,d6
  146.         move.w    d2,d3
  147.         move.l    a2,a3
  148.         add.b    (a1,d7.l),d3            ;d3 = left tile.
  149.         move.l    a0,a4                ;a4 = data out.
  150.         addq.b    #1,d7
  151.         lsl.w    #4,d3                ;d3 = d3 * 16.
  152.         and.b    #%11111,d7
  153.         add.l    d3,a3                ;a3 = data in.
  154.         addq.l    #1,a0                ;next x (after next loop).
  155.  
  156. screen_aga_bdat:move.w    (a3)+,d4            ;d4 = 00.B, 01.B.
  157.         move.b    d4,40(a4)            ;01.B.
  158.         lsr.w    #8,d4
  159.         move.b    d4,(a4)                ;00.B.
  160.         add.l    #40*8,a4
  161.         dbra    d6,screen_aga_bdat        ;do the marginal bytes.
  162.  
  163.         moveq.l    #(160/8)/4-1,d1            ;x.
  164. screen_aga_rows:move.w    d2,d3
  165.         add.b    (a1,d7.l),d3            ;d3 = left tile.
  166.         addq.b    #1,d7
  167.         lsl.w    #4,d3                ;d3 = d3 * 16.
  168.         and.b    #%11111,d7
  169.         lea    (a2,d3.l),a3
  170.  
  171.         move.w    d2,d3
  172.         add.b    (a1,d7.l),d3            ;d3 = left tile.
  173.         addq.b    #1,d7
  174.         lsl.w    #4,d3                ;d3 = d3 * 16.
  175.         and.b    #%11111,d7
  176.         lea    (a2,d3.l),a4
  177.  
  178.         move.w    d2,d3
  179.         add.b    (a1,d7.l),d3            ;d3 = left tile.
  180.         addq.b    #1,d7
  181.         lsl.w    #4,d3                ;d3 = d3 * 16.
  182.         and.b    #%11111,d7
  183.         lea    (a2,d3.l),a5
  184.  
  185.         move.w    d2,d3
  186.         add.b    (a1,d7.l),d3            ;d3 = left tile.
  187.         addq.b    #1,d7
  188.         lsl.w    #4,d3                ;d3 = d3 * 16.
  189.         and.b    #%11111,d7
  190.         lea    (a2,d3.l),a6
  191.  
  192.         moveq.l    #8-1,d6
  193. screen_aga_out:    move.w    (a3)+,d3
  194.         lsl.l    #8,d3
  195.         move.w    d3,d5
  196.         move.w    (a4)+,d3
  197.         move.b    d3,d5
  198.         lsl.l    #8,d5
  199.         lsl.l    #8,d3
  200.         move.w    (a5)+,d3
  201.         move.b    d3,d5
  202.         lsl.l    #8,d5
  203.         move.w    (a6)+,d4
  204.         move.b    d4,d5                ;d5 = p1 data.
  205.         move.l    d5,40(a0)
  206.         lsr.w    #8,d4
  207.         move.b    d4,d3                ;d3 = p0 data.
  208.         move.l    d3,(a0)
  209.         add.l    #8*40,a0
  210.         dbra    d6,screen_aga_out        ;next y.
  211.  
  212.         moveq.l    #0,d3                ;speed up reset.
  213.         sub.l    #8*8*40-4,a0            ;next x.
  214.         dbra    d1,screen_aga_rows        ;next four blocks.
  215.  
  216.         movem.l    (SP)+,d6/d7/a0
  217.         add.l    #8*8*40,a0            ;next y.
  218.         addq.b    #1,d6                ;       (register).
  219.         and.b    #%11111,d6
  220.         beq.s    screen_aga_tup            ;back to beginning.
  221.         add.l    #32,a1                ;next y.
  222.         dbra    d0,screen_aga_colu        ;next 168x8 line.
  223.         rts
  224.  
  225.         cnop    0,4
  226. screen_aga_tup:    sub.l    #32*31,a1            ;back to the beginning.
  227.         dbra    d0,screen_aga_colu        ;next 168x8 line.
  228.         rts
  229.  
  230. ;««««««««««««««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
  231. ;        clear the background
  232. ;««««««««««««««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
  233.  
  234. screen_aga_clear_the_background:
  235.         move.l    aga_map_inactive,a0
  236.         move.w    #256,d0
  237.         moveq.l    #0,d1
  238.  
  239. screen_aga_clear_the_background_loop:
  240.         move.l    d1,(a0)+
  241.         move.l    d1,(a0)+
  242.         move.l    d1,(a0)+
  243.         move.l    d1,(a0)+
  244.         move.l    d1,(a0)+
  245.         move.l    d1,(a0)+
  246.         move.l    d1,(a0)+
  247.         move.l    d1,(a0)+
  248.         move.l    d1,(a0)+
  249.         move.l    d1,(a0)+            ;40.
  250.         move.l    d1,(a0)+
  251.         move.l    d1,(a0)+
  252.         move.l    d1,(a0)+
  253.         move.l    d1,(a0)+
  254.         move.l    d1,(a0)+
  255.         move.l    d1,(a0)+
  256.         move.l    d1,(a0)+
  257.         move.l    d1,(a0)+
  258.         move.l    d1,(a0)+
  259.         move.l    d1,(a0)+            ;80.
  260.         add.l    #(320/8)*6,a0
  261.         dbra    d0,screen_aga_clear_the_background_loop
  262.         rts
  263.  
  264. ;««««««««««««««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
  265. ;        do the sprites
  266. ;««««««««««««««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
  267.  
  268.         cnop    0,4
  269. screen_aga_sprs:move.l    aga_map_inactive,a0        ;the sprite area.
  270.         add.l    #40*8*16+4+40*4,a0        ;a0 = sprite plane 0.
  271.         move.l    #40*8,d2            ;a speed up.
  272.  
  273.         move.l    aga_sprs_inactive,a2
  274.         add.l    #16,a2                ;skip the first 16 rows.
  275.         move.w    #144-1,d0
  276.         cnop    0,4
  277. spr_aga_empty:    tst.b    (a2)
  278.         bne.s    aga_clear_me
  279.         add.l    d2,a0
  280.         addq.l    #1,a2
  281.         dbra    d0,spr_aga_empty
  282.         bra.s    aga_lines_done
  283. aga_clear_me:    clr.b    (a2)+
  284.         moveq.l    #(160+64-32)/8/4-1,d1
  285.         move.l    a0,a1
  286.         lea    40(a0),a3
  287. aga_clear_us:    clr.l    (a1)+
  288.         clr.l    (a3)+
  289.         dbra    d1,aga_clear_us
  290.         add.l    d2,a0
  291.         dbra    d0,spr_aga_empty
  292.  
  293. aga_lines_done:    move.l    aga_map_inactive,a0        ;the sprite area.
  294.         add.l    #40*8*16+4+40*6,a0        ;a0 = sprite plane 2.
  295.  
  296.         move.l    aga_sprs_inactive_x,a2
  297.         add.l    #16,a2                ;skip the first 16 rows.
  298.         move.w    #144-1,d0
  299.         cnop    0,4
  300. xspr_aga_empty:    tst.b    (a2)
  301.         bne.s    xaga_clear_me
  302.         add.l    d2,a0
  303.         addq.l    #1,a2
  304.         dbra    d0,xspr_aga_empty
  305.         bra.s    xaga_lines_done
  306. xaga_clear_me:    clr.b    (a2)+
  307.         moveq.l    #(160+64-32)/8/4-1,d1
  308.         move.l    a0,a1
  309.         lea    40(a0),a3
  310. xaga_clear_us:    clr.l    (a1)+
  311.         clr.l    (a3)+
  312.         dbra    d1,xaga_clear_us
  313.         add.l    d2,a0
  314.         dbra    d0,xspr_aga_empty
  315.  
  316. ;««««««««««««««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
  317. ;        line clearing has been executed
  318. ;««««««««««««««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
  319.  
  320. xaga_lines_done:move.l    lcd_control,d1            ;d1 = lcd control byte.
  321.         btst    #1,d1                ;sprites off?
  322.         beq.w    aga_spr_exit            ;yes.
  323.  
  324.         move.l    gb_memory,a0
  325.         move.l    a0,a1
  326.         add.l    #$fe00+40*4,a0            ;a0 = sprite attribute table.
  327.         add.l    #$8000,a1            ;a1 = sprite pattern table.
  328.         moveq.l    #40-1,d0            ;d0 = number of sprites.
  329.         move.l    #40,d6                ;speed up.
  330.         move.l    x_flip_table,a2            ;        .
  331.  
  332.         btst    #2,d1                ;sprite size?
  333.         bne.w    aspr_n8x16            ;8x16.
  334.  
  335. aspr_n8x8:    move.l    #8-1,sprite_y
  336.         move.b    #$ff,sprite_mask
  337.         bra.s    aspr_c8xq            ;do the copying.
  338. aspr_n8x16:    move.l    #16-1,sprite_y
  339.         move.b    #$fe,sprite_mask
  340.  
  341. ;««««««««««««««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
  342. ;        sprite size 8xq, q=8/16.
  343. ;        INPUT:
  344. ;        d0    = number of sprites.
  345. ;        d6    = 40 (a speed up).
  346. ;        a0    = sprite attribute table.
  347. ;        a1    = sprite pattern area.
  348. ;        a2    = x flip table.
  349. ;««««««««««««««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
  350.  
  351. aspr_c8xq:    move.l    -(a0),d1            ;d1 = y.B, x.B, gfx.B, flags.B.
  352.         move.l    d1,d2
  353.         swap    d2
  354.         tst.b    d2
  355.         beq.w    aspr_xit
  356.         lsr.w    #8,d2
  357.         beq.w    aspr_xit
  358.  
  359. aspr_xcute:    swap    d1                ;d1 = gfx.B, flags.B, y.B, x.B.
  360.         move.l    bg_scroll_x,d2            ;x start (bg scroll pixels).
  361.         add.b    d1,d2                ;d2 = x.B.
  362.         cmp.w    #8+160+8,d2            ;out of vision?
  363.         bge.w    aspr_xit            ;yes.
  364.  
  365.         moveq.l    #0,d3
  366.         ror.w    #8,d1                ;d1 = gfx.B, flags.B, x.B, y.B.
  367.         move.b    d1,d3                ;d3 = y.B.
  368.         cmp.w    #16+144+8,d3            ;out of vision?
  369.         bge.w    aspr_xit            ;yes.
  370.  
  371.         move.l    d3,a3                ;a3 = scanline clear bytes.
  372.  
  373.         move.w    d3,d4
  374.         lsl.w    #8,d4
  375.         lsl.w    #6,d3
  376.         add.w    d4,d3                ;d3 = y on screen.
  377.                             ;(d3 = d3 * 40*8).
  378.         move.l    d2,d4                ;d4 = x.B.
  379.         lsr.w    #3,d4                ;d4 = x.B / 8.
  380.         add.l    d4,d3                ;d3 = y and x fixed.
  381.         move.l    aga_map_inactive,a4
  382.         and.b    #%111,d2            ;d2 = bit skip (0-7).
  383.         add.l    d3,a4                ;a4 = output.
  384.         rol.l    #8,d1                ;d1 = flags.B, x.B, y.B, gfx.B.
  385.         and.b    sprite_mask,d1
  386.         move.b    d1,d4                ;d4 = gfx.B.
  387.         add.l    #40*4+(64/8)-1,a4        ;to sprite planes.
  388.         lsl.w    #4,d4                ;d4 = d4 * 16.
  389.         lea    (a1,d4.l),a6            ;a6 = pattern data.
  390.  
  391.         btst    #4+24,d1            ;palette bit test.
  392.         beq.s    aga_spr_nop            ;palette 0.
  393.         move.l    a4,a5                ;a5 = mask plane.
  394.         add.l    #40*2,a4            ;palette 1.
  395.         add.l    aga_sprs_inactive_x,a3        ;         .
  396.         bra.s    pal_pla_done
  397. aga_spr_nop:    move.l    a4,a5
  398.         add.l    #40*2,a5            ;a5 = mask plane.
  399.         add.l    aga_sprs_inactive,a3        ;palette 0.
  400.  
  401. pal_pla_done:    move.l    sprite_y,d7            ;d7 = y-1.
  402.         btst    #6+24,d1            ;y flipped?
  403.         bne.w    aga_spr_y            ;yes.
  404.         btst    #5+24,d1            ;x flipped?
  405.         bne.s    aga_spr_x            ;yes.
  406.  
  407. ;««««««««««««««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
  408. ;        normal sprite output
  409. ;««««««««««««««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
  410.  
  411.         move.w    #$ffff,d1            ;speed up.
  412.         cnop    0,4
  413. aga_spr_normal:    move.w    (a6)+,d3
  414.         beq.s    aga_spr_nx            ;empty data.
  415.  
  416.         move.b    d3,d4                ;d4 = 01.
  417.         clr.b    d3                ;d3 = 0x.
  418.         lsl.w    #8,d4                ;d4 = 1x.
  419.         lsr.w    d2,d3                ;bits skipped.
  420.         lsr.w    d2,d4                ;bits skipped.
  421.  
  422.         move.w    d3,d5
  423.         move.b    d1,(a3)+            ;this sl must be cleared.
  424.         or.w    d4,d5
  425.         eor.w    d1,d5
  426.  
  427.         and.w    d5,(a4)                ;mask p0.
  428.         or.w    d3,(a4)
  429.         add.l    d6,a4
  430.         and.w    d5,(a4)                ;mask p1.
  431.         or.w    d4,(a4)
  432.         add.l    #40*7,a4            ;next y.
  433.  
  434.         and.w    d5,(a5)
  435.         add.l    d6,a5
  436.         and.w    d5,(a5)
  437.         add.l    #40*7,a5
  438.  
  439.         dbra    d7,aga_spr_normal        ;next y (sprite data).
  440. aspr_xit:    dbra    d0,aspr_c8xq            ;next sprite.
  441.         rts
  442.  
  443.         cnop    0,4
  444. aga_spr_nx:    add.l    #40*8,a4
  445.         addq.l    #1,a3                ;no data here.
  446.         add.l    #40*8,a5
  447.         dbra    d7,aga_spr_normal        ;next y (sprite data).
  448.         dbra    d0,aspr_c8xq            ;next sprite.
  449.         rts
  450.  
  451. ;««««««««««««««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
  452. ;        x flipped sprite output
  453. ;««««««««««««««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
  454.  
  455. aga_spr_x:    moveq.l    #0,d3
  456.         move.w    #$ffff,d1            ;speed up.
  457.         cnop    0,4
  458. aga_spr_xz:    move.w    (a6)+,d3
  459.         beq.s    aga_spr_xx            ;empty data.
  460.         move.w    (a2,d3.l*2),d3            ;x flipped data.
  461.  
  462.         move.b    d3,d4                ;d4 = 01.
  463.         clr.b    d3                ;d3 = 0x.
  464.         lsl.w    #8,d4                ;d4 = 1x.
  465.         lsr.w    d2,d3                ;bits skipped.
  466.         lsr.w    d2,d4                ;bits skipped.
  467.  
  468.         move.w    d3,d5
  469.         move.b    d1,(a3)+            ;this sl must be cleared.
  470.         or.w    d4,d5
  471.         eor.w    d1,d5
  472.  
  473.         and.w    d5,(a4)                ;mask p0.
  474.         or.w    d3,(a4)
  475.         add.l    d6,a4
  476.         and.w    d5,(a4)                ;mask p1.
  477.         or.w    d4,(a4)
  478.         add.l    #40*7,a4            ;next y.
  479.  
  480.         and.w    d5,(a5)
  481.         add.l    d6,a5
  482.         and.w    d5,(a5)
  483.         add.l    #40*7,a5
  484.  
  485.         dbra    d7,aga_spr_xz            ;next y (sprite data).
  486.         dbra    d0,aspr_c8xq            ;next sprite.
  487.         rts
  488.  
  489.         cnop    0,4
  490. aga_spr_xx:    add.l    #40*8,a4
  491.         addq.l    #1,a3                ;no data here.
  492.         add.l    #40*8,a5
  493.         dbra    d7,aga_spr_xz            ;next y (sprite data).
  494.         dbra    d0,aspr_c8xq            ;next sprite.
  495.         rts
  496.  
  497. ;««««««««««««««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
  498. ;        y flipping detected
  499. ;««««««««««««««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
  500.  
  501. aga_spr_y:    move.l    d7,d4
  502.         addq.b    #1,d4
  503.         lsl.b    #1,d4
  504.         add.l    d4,a6                ;to sprite data end.
  505.  
  506.         btst    #5+24,d1            ;x flipped?
  507.         bne.s    aga_spr_xy            ;yes.
  508.  
  509. ;««««««««««««««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
  510. ;        y flipped sprite output
  511. ;««««««««««««««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
  512.  
  513.         move.w    #$ffff,d1            ;speed up.
  514.         cnop    0,4
  515. aga_spr_yz:    move.w    -(a6),d3
  516.         beq.s    aga_spr_ny            ;empty data.
  517.  
  518.         move.b    d3,d4                ;d4 = 01.
  519.         clr.b    d3                ;d3 = 0x.
  520.         lsl.w    #8,d4                ;d4 = 1x.
  521.         lsr.w    d2,d3                ;bits skipped.
  522.         lsr.w    d2,d4                ;bits skipped.
  523.  
  524.         move.w    d3,d5
  525.         move.b    d1,(a3)+            ;this sl must be cleared.
  526.         or.w    d4,d5
  527.         eor.w    d1,d5
  528.  
  529.         and.w    d5,(a4)                ;mask p0.
  530.         or.w    d3,(a4)
  531.         add.l    d6,a4
  532.         and.w    d5,(a4)                ;mask p1.
  533.         or.w    d4,(a4)
  534.         add.l    #40*7,a4            ;next y.
  535.  
  536.         and.w    d5,(a5)
  537.         add.l    d6,a5
  538.         and.w    d5,(a5)
  539.         add.l    #40*7,a5
  540.  
  541.         dbra    d7,aga_spr_yz            ;next y (sprite data).
  542.         dbra    d0,aspr_c8xq            ;next sprite.
  543.         rts
  544.  
  545.         cnop    0,4
  546. aga_spr_ny:    add.l    #40*8,a4
  547.         addq.l    #1,a3                ;no data here.
  548.         add.l    #40*8,a5
  549.         dbra    d7,aga_spr_yz            ;next y (sprite data).
  550.         dbra    d0,aspr_c8xq            ;next sprite.
  551.         rts
  552.  
  553. ;««««««««««««««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
  554. ;        x flipped sprite output
  555. ;««««««««««««««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
  556.  
  557. aga_spr_xy:    moveq.l    #0,d3
  558.         move.w    #$ffff,d1            ;speed up.
  559.         cnop    0,4
  560. aga_spr_xyz:    move.w    -(a6),d3
  561.         beq.s    aga_spr_xyx            ;empty data.
  562.         move.w    (a2,d3.l*2),d3            ;x flipped data.
  563.  
  564.         move.b    d3,d4                ;d4 = 01.
  565.         clr.b    d3                ;d3 = 0x.
  566.         lsl.w    #8,d4                ;d4 = 1x.
  567.         lsr.w    d2,d3                ;bits skipped.
  568.         lsr.w    d2,d4                ;bits skipped.
  569.  
  570.         move.w    d3,d5
  571.         move.b    d1,(a3)+            ;this sl must be cleared.
  572.         or.w    d4,d5
  573.         eor.w    d1,d5
  574.  
  575.         and.w    d5,(a4)                ;mask p0.
  576.         or.w    d3,(a4)
  577.         add.l    d6,a4
  578.         and.w    d5,(a4)                ;mask p1.
  579.         or.w    d4,(a4)
  580.         add.l    #40*7,a4            ;next y.
  581.  
  582.         and.w    d5,(a5)
  583.         add.l    d6,a5
  584.         and.w    d5,(a5)
  585.         add.l    #40*7,a5
  586.  
  587.         dbra    d7,aga_spr_xyz            ;next y (sprite data).
  588.         dbra    d0,aspr_c8xq            ;next sprite.
  589.         rts
  590.  
  591.         cnop    0,4
  592. aga_spr_xyx:    add.l    #40*8,a4
  593.         addq.l    #1,a3                ;no data here.
  594.         add.l    #40*8,a5
  595.         dbra    d7,aga_spr_xyz            ;next y (sprite data).
  596.         dbra    d0,aspr_c8xq            ;next sprite.
  597.         rts
  598.  
  599. ;««««««««««««««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
  600. ;        draw the h/w window using amiga sprites
  601. ;««««««««««««««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
  602.  
  603.         cnop    0,4
  604. screen_aga_win:    move.l    lcd_control,d0            ;d0 = lcd control byte.
  605.         btst    #5,d0                ;window display?
  606.         beq.w    screen_aga_wxt            ;nope.
  607.         btst    #0,d0
  608.         beq.w    screen_aga_wxt
  609.  
  610.         move.l    gb_memory,a0
  611.         move.l    a0,a2
  612.  
  613.         add.l    #$9800,a0            ;window tiles.
  614.         and.b    #%1000000,d0            ;d0 = tile position.
  615.         lsl.w    #4,d0                ;d0 = 0/1 * 1024.
  616.         add.l    d0,a0                ;a0 = window tiles.
  617.  
  618.         move.l    gb_tiles,a1
  619.  
  620.         add.l    #$ff4a,a2            ;a2 = window y position.
  621.         moveq.l    #0,d0
  622.         move.b    (a2)+,d0            ;d0 = window y pos ($ff4A).
  623.         moveq.l    #0,d1
  624.         move.b    (a2),d1                ;d1 = window x pos ($ff4B).
  625.         cmp.b    #6,d1
  626.         bne.s    win_aga_no_no
  627.         addq.b    #1,d1
  628.  
  629. ;««««««««««««««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
  630. ;        INPUT:
  631. ;        d0    = window y position.
  632. ;        d1    =        x         .
  633. ;        a0    = window tiles.
  634. ;        a1    = window tile pattern table.
  635. ;««««««««««««««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
  636.  
  637. win_aga_no_no:    cmp.w    #160,d1
  638.         bge.w    screen_aga_wxt
  639.         cmp.w    #144,d0
  640.         bge.w    screen_aga_wxt
  641.         move.l    d0,-(SP)
  642.  
  643.         add.w    #$2c,d0
  644.         add.w    #$81+64-8,d1
  645.  
  646.         lsl.w    #8,d0
  647.         moveq.l    #3-1,d2                ;max three 64x144 sprites.
  648.         move.l    aga_spr_inactive_pointer,a2    ;pointers to the sprites.
  649.         move.w    #(144+2*16+12)*256,d4        ;d4 = y end of sprite.
  650.         move.w    d1,d3
  651.         move.b    d1,d4
  652.         lsr.w    #1,d3                ;d3 = x / 2.
  653.         and.b    #%1,d4                ;d4 = sho bit.
  654.         lea    aga_spr_Ix,a5            ;mask sprites.
  655.         moveq.l    #-1,d6                ;d6 = visible sprite number.
  656. win_aga_pointer:move.l    (a2)+,a3
  657.         move.w    d0,d5
  658.         move.l    (a5)+,a4
  659.         move.b    d3,d5
  660.         move.w    d5,(a3)
  661.         move.w    d4,d7
  662.         move.w    d5,(a4)
  663.         addq.l    #8,a3
  664.         addq.l    #8,a4
  665.         move.w    d7,(a3)
  666.         addq.w    #1,d6                ;one sprite more visible.
  667.         move.w    d7,(a4)
  668.         add.w    #64,d1
  669.         cmp.w    #$81+64-8+64*3,d1
  670.         bge.s    win_aga_no_more            ;no more sprites.
  671.         add.b    #64/2,d3            ;64 pixels right.
  672.         dbra    d2,win_aga_pointer
  673.         bra.s    no_empty_sprs
  674.  
  675. win_aga_no_more:dbra    d2,win_aga_mush            ;empty the next sprites.
  676.         bra.s    no_empty_sprs
  677.  
  678. win_aga_mush:    move.l    (a2)+,a3
  679.         move.w    d5,(a3)
  680.         addq.l    #8,a3
  681.         move.l    (a5)+,a4
  682.         move.w    d5,(a4)
  683.         addq.l    #8,a4
  684.         move.w    d7,(a3)
  685.         move.w    d7,(a4)        
  686.         dbra    d2,win_aga_mush            ;empty the next sprites.
  687.  
  688. ;««««««««««««««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
  689. ;        prepare for the data transfer
  690. ;        INPUT:
  691. ;        d6    = number of used sprites - 1.
  692. ;        a0    = window tiles.
  693. ;        a1    = window tile pattern table.
  694. ;««««««««««««««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
  695.  
  696. no_empty_sprs:    move.l    #144,d0
  697.         sub.l    (SP)+,d1
  698.         lsr.b    #3,d0                ;d0 = dy/8.
  699.         move.l    aga_spr_inactive_pointer,a2    ;a2 = pointer to the sprite
  700.                             ;pointers.
  701. ;««««««««««««««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
  702. ;        copy data to sprites
  703. ;        INPUT:
  704. ;        d0    = delta y / 8.
  705. ;        d6    = number of used sprites - 1.
  706. ;        a0    = window tiles.
  707. ;        a1    = window tile pattern table.
  708. ;        a2    = pointer to the sprite pointers.
  709. ;««««««««««««««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
  710.  
  711.         cnop    0,4
  712. aga_window_fill:move.l    (a2)+,a6
  713.         movem.l    d0/d6/a0/a2,-(SP)
  714.         add.l    #16,a6                ;skip the control words.
  715.  
  716. aga_win_data_cp:moveq.l    #2-1,d7
  717. aga_win_data_do:move.l    tile_adder,d1
  718.         move.l    d1,d2
  719.         move.l    d1,d3
  720.         move.l    d1,d4
  721.         move.l    (a0)+,d5
  722.         add.b    d5,d4
  723.         lsr.l    #8,d5
  724.         add.b    d5,d3
  725.         lsr.l    #8,d5
  726.         add.b    d5,d2
  727.         lsr.w    #8,d5
  728.         add.b    d5,d1
  729.         lsl.w    #4,d4
  730.         lsl.w    #4,d3
  731.         lsl.w    #4,d2
  732.         lsl.w    #4,d1
  733.         lea    (a1,d4.l),a5            ;xxx1.
  734.         lea    (a1,d3.l),a4            ;xx1x.
  735.         lea    (a1,d2.l),a3            ;x1xx.
  736.         lea    (a1,d1.l),a2            ;1xxx.
  737.  
  738.         moveq.l    #8-1,d6
  739. aga_win_data_mv:move.w    (a2)+,d5
  740.         move.b    d5,d4
  741.         lsl.w    #8,d4
  742.         lsl.l    #8,d5
  743.         move.w    (a3)+,d5
  744.         move.b    d5,d4
  745.         lsl.l    #8,d5
  746.         lsl.l    #8,d4
  747.         move.w    (a4)+,d5
  748.         move.b    d5,d4
  749.         lsl.l    #8,d4
  750.         move.w    (a5)+,d3
  751.         move.b    d3,d4
  752.         move.l    d4,8(a6)
  753.         lsr.w    #8,d3
  754.         move.b    d3,d5
  755.         move.l    d5,(a6)
  756.         add.l    #16,a6
  757.         dbra    d6,aga_win_data_mv
  758.         sub.l    #16*8-4,a6            ;next x.
  759.         dbra    d7,aga_win_data_do
  760.         add.l    #16*8-8,a6            ;next y column.
  761.         add.l    #32-4-4,a0            ;             .
  762.         dbra    d0,aga_win_data_cp        ;next 64 x 8 line.
  763.         movem.l    (SP)+,d0/d6/a0/a2
  764.         addq.l    #8,a0
  765.         dbra    d6,aga_window_fill        ;next sprite.
  766.         rts
  767.  
  768. ;««««««««««««««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
  769. ;        move all the sprites away from the view
  770. ;««««««««««««««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
  771.  
  772. screen_aga_wxt:    moveq.l    #3-1,d0
  773.         move.l    aga_spr_inactive_pointer,a0
  774. not_visible_spr:move.l    (a0)+,a1
  775.         move.b    #32*6,1(a1)
  776.         dbra    d0,not_visible_spr
  777.         rts
  778.